using System;
namespace AppToolKit.Core
{
	public class TypeHelper
	{
		public static bool IsStringType(Type type)
		{
			return type == typeof(string);
		}
		public static bool IsInheritInterface(Type target, Type interace)
		{
			if (!interace.IsInterface)
			{
				throw new ArgumentException("interface只能是接口");
			}
			Type[] interfaces = target.GetInterfaces();
			bool result;
			for (int i = 0; i < interfaces.Length; i++)
			{
				Type type = interfaces[i];
				if (type.Equals(interace))
				{
					result = true;
					return result;
				}
			}
			result = false;
			return result;
		}
		public static bool IsInheritGenericInterface(Type target, Type interace)
		{
			if (!interace.IsInterface || !interace.IsGenericTypeDefinition)
			{
				throw new ArgumentException("interface只能是范型接口");
			}
			Type[] interfaces = target.GetInterfaces();
			bool result;
			for (int i = 0; i < interfaces.Length; i++)
			{
				Type type = interfaces[i];
				if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(interace))
				{
					result = true;
					return result;
				}
			}
			result = false;
			return result;
		}
		public static bool IsGeneric(Type target, Type genericeTypeDefine)
		{
			if (!genericeTypeDefine.IsGenericTypeDefinition)
			{
				throw new ArgumentException("genericeDefine只能范型");
			}
			if (!target.IsGenericType)
			{
				throw new ArgumentException("target只能范型");
			}
			bool result;
			if (target.IsGenericType)
			{
				if (target.GetGenericTypeDefinition().Equals(genericeTypeDefine))
				{
					result = true;
					return result;
				}
			}
			result = false;
			return result;
		}
	}
}
